	import model.UserModel;
	import mx.controls.Alert;
	import nrb.utils.DateHandler;
	import nrb.utils.XMLHelper;
	
	
	
	[Bindable] private var xml_users:XML;
	private var helper_xml:XMLHelper;
	public var user_model:UserModel;
	private var dates:DateHandler;
	private var pA:Object;
	
	public function func_init(): void {
		xml_users = new XML();
		helper_xml = new XMLHelper();
		user_model = new UserModel();
		dates = new DateHandler();
		pA = new Object();
		
		pA = parentApplication;
		func_get_logged_user();
	}
	
	private function func_get_logged_user(): void {
		//check if xml already exists
		if (!helper_xml.func_check_fileexists(pA.FILENAME_USERS_XML)){
			Alert.show('No File Found');
		}else{
			helper_xml.func_open_xml(pA.FILENAME_USERS_XML);
			xml_users = helper_xml.func_get_xml();
			func_init_fields();
		}
	}
	
	
	private function func_init_fields(): void {
		var obj_user:Object = new Object();
		obj_user = xml_users.user.(userid == pA.LOGGED_USER_ID && password == pA.LOGGED_PASSWORD);
		user_model.func_set_attributes(obj_user);
		
		txt_userid.text = user_model.userid;
		txt_password.text = user_model.password;
		txt_username.text = user_model.username;
		txt_userrole.text = user_model.userrole;
		txt_userdescription.text = user_model.userdescription;
	}
	
	private function func_update(): void {
		xml_users.user.(userid == pA.LOGGED_USER_ID && password == pA.LOGGED_PASSWORD).password = txt_password.text;
		xml_users.user.(userid == pA.LOGGED_USER_ID && password == pA.LOGGED_PASSWORD).username = txt_username.text;
		xml_users.user.(userid == pA.LOGGED_USER_ID && password == pA.LOGGED_PASSWORD).userdescription = txt_userdescription.text;
		xml_users.user.(userid == pA.LOGGED_USER_ID && password == pA.LOGGED_PASSWORD).datemodified = dates.get_full_date('YYYY-MM-DD HH:NN:SS')
		xml_users.user.(userid == pA.LOGGED_USER_ID && password == pA.LOGGED_PASSWORD).modifiedby = pA.LOGGED_USER_ID;
		helper_xml.func_write_xml(xml_users);
		Alert.show('Profile Updated');
	}
	
	